home *** CD-ROM | disk | FTP | other *** search
/ Programmer Power Tools / Programmer Power Tools.iso / surfmodl / surfm203.arc / SURFSRC.ARC / GETONE.INC < prev    next >
Text File  |  1987-12-21  |  2KB  |  58 lines

  1. { GETONEREAL and GETONEINT: Two functions that do the same thing.
  2.   They both print a prompt and the old value of the variable, and
  3.   request a new value from the user.  If the user just hits ENTER,
  4.   then the old value is returned.  If he types in a legitimate value
  5.   (i.e., it is numeric and in the range Loval to Hival), then the
  6.   new value is returned.  If an invalid entry is made, he is given
  7.   an error message and prompted to retype.
  8. }
  9.  
  10. function GETONEREAL (Oldval, Loval, Hival: real; Prompt: text80): real;
  11. var Num:     integer;        { number of values read }
  12.     Realvar: vartype;        { variables from input }
  13.     Comment: text80;         { user's comment (unused) }
  14.  
  15. begin
  16.   Num := -1;
  17.   while (Num <> 0) and (Num <> 1) do begin
  18.     write ('Enter ', Prompt, ' ( ', Oldval:7:3, ' ) = ');
  19.     Num := inreal (Input, Realvar, Comment, 0, TRUE);
  20.     if (Num = 1) then begin
  21.       if (Realvar[1] < Loval) or (Realvar[1] > Hival) then begin
  22.         writeln ('Error: Input must be in range ', Loval:7:3, ' to ',
  23.                  Hival:7:3);
  24.         Num := -1;
  25.       end;
  26.     end else if (Num <> 0) then
  27.       writeln ('Error: Expecting one numeric input.');
  28.   end; { while }
  29.   if (Num = 1) then
  30.     Getonereal := Realvar[1]
  31.   else
  32.     Getonereal := Oldval;
  33. end; { function GETONEREAL }
  34.  
  35. function GETONEINT (Oldval, Loval, Hival: integer; Prompt: text80): integer;
  36. var Num:     integer;        { number of values read }
  37.     Realvar: vartype;        { variables from input }
  38.     Comment: text80;         { user's comment (unused) }
  39.  
  40. begin
  41.   Num := -1;
  42.   while (Num <> 0) and (Num <> 1) do begin
  43.     write ('Enter ', Prompt, ' ( ', Oldval, ' ) = ');
  44.     Num := inreal (Input, Realvar, Comment, 0, TRUE);
  45.     if (Num = 1) then begin
  46.       if (Realvar[1] < Loval) or (Realvar[1] > Hival) then begin
  47.         writeln ('Error: Input must be in range ', Loval, ' to ', Hival);
  48.         Num := -1;
  49.       end;
  50.     end else if (Num <> 0) then
  51.       writeln ('Error: Expecting one numeric input.');
  52.   end; { while }
  53.   if (Num = 1) then
  54.     Getoneint := round (Realvar[1])
  55.   else
  56.     Getoneint := Oldval;
  57. end; { function GETONEINT }
  58.